package com.bw.zg3park2212.fg

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.Gravity
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.GravityCompat
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.bumptech.glide.Glide
import com.bw.base.mvvm.BaseViewFram
import com.bw.zg3park2212.R
import com.bw.zg3park2212.databinding.FragmentBlank5Binding
import com.github.gzuliyujiang.wheelpicker.AddressPicker
import com.github.gzuliyujiang.wheelpicker.DatePicker
import com.github.gzuliyujiang.wheelpicker.OptionPicker
import com.github.gzuliyujiang.wheelpicker.TimePicker
import com.github.gzuliyujiang.wheelpicker.annotation.AddressMode
import com.github.gzuliyujiang.wheelpicker.entity.DateEntity
import com.wildma.pictureselector.PictureBean
import com.wildma.pictureselector.PictureSelector
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class BlankFragment5 : BaseViewFram<FragmentBlank5Binding>() {
    override fun intitView() {
        binding.jffw.setOnClickListener {
            ARouter.getInstance().build("/app/PaylerActivity").navigation()
        }
        binding.wdhy.setOnClickListener {
            ARouter.getInstance().build("/app/MemActivity").navigation()
        }
        binding.mychange.setOnClickListener {
            SPUtils.getInstance().remove("token")
            SPUtils.getInstance().remove("userid")
            ARouter.getInstance().build("/app/LoginActivity").navigation()
        }
        binding.wdsq.setOnClickListener {
            ARouter.getInstance().build("/app/ApplyActivity").navigation()
        }
        //出副布局
        binding.myEdit.setOnClickListener {
            binding.dlt.openDrawer(GravityCompat.END)
        }
        binding.icon.setOnClickListener {
            PictureSelector.create(this,100).selectPicture()
        }
        binding.sex.setOnClickListener {
            val list= mutableListOf<String>("男","女")
            val optionPicker= OptionPicker(requireActivity())
            optionPicker.setData(list)
            optionPicker.setOnOptionPickedListener { position, item ->
                binding.sex.text="性别:"+item
            }
            optionPicker.show()
        }
        binding.day.setOnClickListener {
            var datePicker=DatePicker(requireActivity())
            datePicker.wheelLayout.setRange(DateEntity.target(1900,1,1), DateEntity.today(), DateEntity.today())
            datePicker.setOnDatePickedListener { year, month, day ->
                binding.day.text="生日:"+year+"年"+month+"月"+day+"日"
            }
            datePicker.show()
        }
        binding.address.setOnClickListener {
            var addressPicker=AddressPicker(requireActivity())
            addressPicker.setAddressMode(AddressMode.PROVINCE_CITY_COUNTY)
            addressPicker.setOnAddressPickedListener { province, city, county ->
                binding.address.text="地址:"+province.name+"-"+city.name+"-"+county.name
            }
            addressPicker.show()
        }
    }

    override fun intitData() {

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 100 && resultCode == Activity.RESULT_OK) {
            val pictureBean = data?.extras?.get(PictureSelector.PICTURE_RESULT) as PictureBean
            Glide.with(this).load(pictureBean.path).into(binding.icon)
            Glide.with(this).load(pictureBean.path).into(binding.myIcon)
        }
    }
}